﻿using System;
using System.Reflection;
using System.Windows.Input;
using MDCAdminTool.Commands;
using Microsoft.ApplicationServer.Caching.AdminApi;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IntegrationTests
{

    [TestClass()]
    public class StopCacheHostTest : BaseTest
    {

        [TestInitialize()]
        public void MyTestInitialize()
        {
            Cluster.Start();
            //WaitForStatus(Cluster, ServiceStatus.Up);

            Hosts(Cluster)[0].Start();
            //WaitForStatus(Hosts(Cluster)[0], ServiceStatus.Up);
        }

        [TestMethod()]
        public void StopCacheHostConstructorTest()
        {
            StopCacheHost target = new StopCacheHost();
        }

        [TestMethod()]
        [TimeoutAttribute(60000)]
        [DeploymentItem("MDCAdminTool.exe")]
        public void OnCanExecuteTest()
        {
            StopCacheHost_Accessor target = new StopCacheHost_Accessor();
            object sender = null;

            CanExecuteRoutedEventArgs e = makeCanExecuteRouteEventArgs(target, Hosts()[0]);

            Hosts(Cluster)[0].Stop();
            //WaitForStatus(Hosts(Cluster)[0], ServiceStatus.Down);

            target.OnCanExecute(sender, e);
            Assert.AreEqual(false, e.CanExecute);

            Hosts(Cluster)[0].Start();

            target.OnCanExecute(sender, e);
            Assert.AreEqual(true, e.CanExecute);

            //WaitForStatus(Hosts(Cluster)[0], ServiceStatus.Up);

            target.OnCanExecute(sender, e);
            Assert.AreEqual(true, e.CanExecute);
        }

        [TestMethod()]
        [TimeoutAttribute(60000)]
        [DeploymentItem("MDCAdminTool.exe")]
        public void OnExecutedTest()
        {
            StopCacheHost_Accessor target = new StopCacheHost_Accessor();
            object sender = null;
            ExecutedRoutedEventArgs e = makeExecutedRoutedEventArgs(target, Hosts()[0]);

            target.OnExecuted(sender, e);

            //WaitForStatus(Hosts(Cluster)[0], ServiceStatus.Down);
            Assert.AreEqual(ServiceStatus.Down, Hosts(Cluster)[0].Status);
        }

    }
}
